import Vue from "vue";
import Vuex from "vuex";
import { removeToken } from "@/utils/auth";
import solarPower from "./solarPower";
import createPersistedstate from "vuex-persistedstate";

Vue.use(Vuex);

export default new Vuex.Store({
    state: {
        token: "",
    },
    getters: {},
    mutations: {
        SET_TOKEN: (state, token) => {
            state.token = token;
            localStorage.setItem("token", token);
        },
    },
    actions: {
        // 退出系统
        LogOut({ commit, state }) {
            return new Promise((resolve, reject) => {
                commit("SET_TOKEN", "");
                removeToken();
                resolve();
            });
        },
    },
    modules: {
        solarPower,
    },
    plugins: [
        createPersistedstate({
            key: "store", // 存数据的key名   自定义的  要有语义化
            // paths: ["solarPower"], // 要把那些模块加入缓存
        }),
    ],
});
